package com.alks.function.mapper.produce;

import com.alks.entity.data.entity.PcCuttingLsLabel;
import com.alks.entity.data.entity.SdCompany;
import com.alks.entity.data.entity.dispatch.*;
import com.alks.entity.data.entity.imes.StyleInfo;
import com.alks.function.data.dto.produce.*;
import com.alks.function.data.request.chengKong.LotNoToStyleRequest;
import com.alks.function.data.request.produce.deleteRequest;
import com.alks.function.data.request.produce.dispatchHeadRequest;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.*;

@Mapper
public interface CuttingDispatchHeadMapper {

    /**
     * 冲裁派工查询
     * @param request
     * @return
     */
    List<PcCuttingDispatchHeadDto> getCuttingDispatchHeadList(dispatchHeadRequest request);

    /**
     * 派工号码明细
     * @param request
     * @return
     */
    List<dispatchDetailDto> getCuttingDispatchDetailList(dispatchHeadRequest request);

    /**
     * 查询可冲裁指令
     * @param companyId
     * @param request
     * @return
     */
    List<CutDispatchLotDto> getCanDispatchLotNoList(@Param("companyId") String companyId,@Param("t") LotNoToStyleRequest request);

    /**
     * 查询指令是否存在
     * @param companyId
     * @param lotNo
     * @return
     */
    CutDispatchLotDto getCanDispatchLotNo(String companyId, String lotNo);

    /**
     * 查询可冲裁的合并指令轮次标签
     * @param companyId
     * @param lotNo
     * @param lsNos
     * @return
     */
    List<LabelPartNameDto> selectUnDispatchCombineLabel(String companyId,String lotNo, List<String> lsNos);

    /**
     * 查询订单指令下的尺码数量发生变化的条数(合并指令)
     * @param lotNo
     * @return
     */
    int selectSizeQtyChangeNumCombine(String lotNo);

    /**
     * 查询可冲裁的未合并指令轮次标签
     * @param companyId
     * @param lotNo
     * @param lsNos
     * @return
     */
    List<LabelPartNameDto> selectUnDispatchLabel(String companyId, String lotNo, List<String> lsNos);

    /**
     * 查询订单指令下的尺码数量发生变化的条数(非合并指令)
     * @param lotNo
     * @return
     */
    int selectSizeQtyChangeNum(String lotNo);

    List<ManulDispatchHead> searchList(ManulDispatchHead manulDispatchHead);

    List<ManulDispatchDetail> dispatchDetailSizeList(ManulDispatchHead manulDispatchHead);

    /**
     * 合并指令轮次
     * @param companyId
     * @param lotNo
     * @return
     */
    List<Integer> selectUnDispatchLsNoByCombineLot(String companyId, String lotNo);

    /**
     * 查询未合并指令轮次
     * @param companyId
     * @param lotNo
     * @return
     */
    List<Integer> selectUnDispatchLsNoByLotNo(String companyId, String lotNo);

    ManulDispatchHead selectByRowids(@Param("re") ManulDispatchHead head, @Param("processCode") String processCode);

    List<DispatchCollection> queryByDispatchNo(String dispatchNo);

    int queryByDispatchNoAndPartName(CuttingDispatchHead param);

    void deleteByDispatchNo(ManulDispatchHead head);

    void deleteByDispatchHeadNo(ManulDispatchHead head);

    void deleteByHead(ManulDispatchHead head);

    void deleteByRowids(@Param("list") List<ManulDispatchHead> list, @Param("processCode") String processCode);

    List<ManulDispatchHead> selectByDispatchType(String dispatchType);

    LotHead getLotHead(LotHead lotHead);

    List<StyleType> selectStyleRemakrByType(StyleInfo param);

    SdCompany getCompanyById(String companyId);

    List<ManulDispatchDetail> selectByDispatchDetailType(@Param("companyId") String companyId, @Param("dispatchType") String dispatchType);

    void updatePrintStatus(@Param("companyId") String companyId, @Param("dispatchNo") String dispatchNo);

    List<Map<String, Object>> returnLotNo(@Param("companyId") String companyId, @Param("searchKey") String searchKey);

    List<Map<String, Object>> returnRoundAndPro(LotHead lotHead);

    List<LotHead> getLotPlanDate(@Param("companyId") String companyId, @Param("lotNo") String lotNo);

    List<ManulDispatchTreeData> selectUnfinishLsNo(@Param("lotHead") LotHead lotHead, @Param("lsNos") List<String> lsNos, @Param("process") List<String> process);


    /**
     * 查询合并指令号码
     * @param companyId
     * @param lotNo
     * @param lsNos
     * @return
     */
    List<Map<String, String>> selectUnDispatchCombineSizeNo(String companyId, String lotNo, List<String> lsNos);

    /**
     * 查询未合并指令号码
     * @param companyId
     * @param lotNo
     * @param lsNos
     * @return
     */
    List<Map<String, String>> selectUnDispatchSizeNo(String companyId, String lotNo, List<String> lsNos);

    /**
     * 当日点检信息查询
     * @param companyId
     * @param dispatchDate
     * @param cutWorkerName
     */
    List<CuttingCheckerDto> loadCuttingCheckerList2(String companyId, LocalDate dispatchDate, String cutWorkerName);

    /**
     * 派工明细
     * @param companyId
     * @param dispatchDate
     * @param workerId
     */
    List<PcCuttingDispatchHeadDto> getPcCuttingDispatchHeadList(String companyId, LocalDate dispatchDate, String workerId);

    /**
     * 查询冲工人员信息
     * @param companyId
     * @param cutWorkerId
     */
    CuttingCheckerDto selectCutWorkerRelation(String companyId, String cutWorkerId);

    /**
     * 查询标签信息
     * @param labelNos
     * @param companyId
     */
    List<PcCuttingLsLabel> selectUnDispatchByLabelNos(List<String> labelNos, String companyId);

    /**
     * 查询最大派工号码
     * @return
     */
    Integer selectPlanNoMax();

    /**
     * 派工单信息
     * @param headList
     */
    int addPcCuttingDispatchHeadList(List<CuttingDispatchHead> headList);

    /**
     * 派工号码
     * @param detailList
     */
    int addPcCuttingDispatchDetailList(List<CuttingDispatchDetail> detailList);

    List<LotPartCombineInfo> selectByLotNo(LotPartCombineInfo lotPartCombineInfo);

    /**
     * 获取最大袋装数量
     * @param companyId
     * @param subLotNoSet
     * @param partName
     * @return
     */
    Integer getMaxConfigBagQty(String companyId, Set<String> subLotNoSet, String partName);

    /**
     * 修改
     * @param companyId
     * @param labelNos
     * @param planNo
     * @param cutWorkerName
     * @param cutWorkerId
     * @param deptNo
     * @param deptName
     * @param lotNo
     * @return
     */
    int updateCombineDispatchNo(@Param("companyId") String companyId, @Param("labelNos") ArrayList labelNos, @Param("planNo") String planNo, @Param("workerName") String cutWorkerName, @Param("workerId") String cutWorkerId, @Param("deptNo") String deptNo, @Param("deptName") String deptName, @Param("combineLabel") String lotNo);

    int addLotLabelCombineInfo(LotLabelCombineInfo combineLabel);

    int updateDispatchNo(@Param("companyId") String companyId, @Param("labelNos") List<String> labelNos, @Param("planNo") String planNo, @Param("workerName") String cutWorkerName, @Param("workerId") String cutWorkerId, @Param("deptNo") String deptNo, @Param("deptName") String deptName);

    List<Map<String, Object>> loadManulWorkerList(@Param("companyId") String companyId, @Param("dispatchDate") Date dispatchDate, @Param("name") String name);

    Employee selectByWorkerIdDisPatch(@Param("companyId") String companyId, @Param("workerId") String workerId);

    ManulDispatchTreeData selectLsRemainQty2(ManulDispatchDetail mdd);

    void batchInsert1(@Param("list") List<ManulDispatchHead> list);

    void batchInsert2(@Param("list") List<ManulDispatchDetail> list);

    List<ManulDispatchHead> selectByDispatchDate(@Param("companyId") String companyId, @Param("beginDate") Date beginDate, @Param("endDate") Date endDate);

    Integer selectSizeSeq(ManulDispatchDetail mdd);

    /**
     * 查询派工信息
     * @param companyId
     * @param request
     * @return
     */
    List<CuttingDispatchHead> getCuttingDispatchHeadByRequest(@Param("companyId") String companyId, @Param("list") List<deleteRequest> request);

    /**
     * 删除派工信息
     * @param head
     * @return
     */
    int deleteByPartNamePlanNo(CuttingDispatchHead head);

    /**
     * 查询派工单是否扫描入库
     * @param companyId
     * @param planNo
     * @param partName
     * @return
     */
    int countHasCollectLabel(String companyId, String planNo, String partName);

    /**
     * 修改标签为未派工
     * @param head
     * @return
     */
    int clearDispatchInfo(CuttingDispatchHead head);

    /**
     * 删除派工号码信息
     * @param head
     */
    int deleteByDispatchHead(CuttingDispatchHead head);

    /**
     * 删除合并指令信息
     * @param head
     */
    int deleteByPartNameDispatchNo(CuttingDispatchHead head);

    /**
     * 查询冲裁派工信息
     *
     * @param companyId
     * @param loginName
     * @param beginDate
     * @param endDate
     * @return
     */
    List<CuttingDispatchHead> selectByDispatchDate2(@Param("companyId") String companyId,@Param("loginName") String loginName, @Param("beginDate") LocalDate beginDate, @Param("endDate") LocalDate endDate);

    /**
     * 查询打印的派工单
     * @param request
     * @return
     */
    List<String> searchPlanNo(dispatchHeadRequest request);

    /**
     * 修改标签打印状态
     * @param companyId
     * @param planNos
     * @return
     */
    int updatePrintLableFlag(String companyId, List<String> planNos);

    /**
     * 查询可打印的标签信息
     * @param companyId
     * @param planNos
     * @return
     */
    List<CuttingRoundLabel> selectByPlanNos(@Param("companyId") String companyId, @Param("planNos") List<String> planNos);

    /**
     * 查询未打印的派工信息
     * @param companyId
     * @param loginName
     * @return
     */
    List<String> selectUnPrintLabel(@Param("companyId") String companyId, @Param("loginName") String loginName);

    /**
     * 查询派工信息
     * @param companyId
     * @param planNo
     * @return
     */
    List<CuttingDispatchHead> selectByPlanNo(@Param("companyId") String companyId, @Param("planNo") String planNo);

    List<CuttingDispatchDetail> selectPdfByPlanNo(String planNo);

    int updatePrintFlag(String companyId, String planNo);

    List<Map<String, Object>> getManulLsSizeNo(@Param("lotHead") LotHead lotHead, @Param("lsNos") List<String> lsNos, @Param("process") List<String> process);

    void insertIntoO(@Param("head") ManulDispatchHead head, @Param("loginName") String loginName);

    @Select("select max(CAST(substring(dispatch_type,2,10) AS UNSIGNED INTEGER)) from PC_CUTTING_DISPATCH_OTHER  where DISPATCH_DEPT =#{dept}")
    Integer selectMaxDispatchType(@Param("dept") String dept);

    List<ManulDispatchDetail> searchListOther(ManulDispatchHead head1);

    List<CuttingDispatchHead> searchDispatchDeadCountList(@Param("companyId") String companyId, @Param("lotNo") String lotNo);
}
